﻿// JScript 文件
/*
    显示左边菜单
*/
function LeftMenu()
{   
    this.m_object={};
    
    this.AddMenuItem = function(object, DiryList)
    {
        this.m_object = object;
        
        var objParent = document.getElementById("CategoryTree");
        if(DiryList.ParentID != 0)
        {
            objParent = document.getElementById("li_" + DiryList.ParentID);
        }
        for(var i = 0; i < DiryList.DirList.length; i++)
        {
            var DirInfo = DiryList.DirList[i];
            var ul = document.createElement("ul");
	        ul.id = "ulTree_"+ DirInfo.ID;
	        if (!DirInfo.IsHasChild) //如果已没有下一级节点
	        {
		        var li = document.createElement("li");
		        li.className = "Child";
		        li.id = "li_" + DirInfo.ID;
    			
    			li.innerHTML = '<img src="../../css/s.gif" class="s" id="' + DirInfo.ID + '"  onclick="LeftMenu.OnItemTextClick('+DirInfo.ID+', \''+DirInfo.Name+'\', '+DiryList.ParentID+')" />';
//		        var img = document.createElement("img");
//		        img.id = DirInfo.ID;
//		        img.className = "s";
//		        img.onclick = function () {
//			        //LeftMenu.OnItemClick(DirInfo.ID, DirInfo.Name, DiryList.ParentID);
//		        };
//		        img.src = "../../css/s.gif";
    			
		        var a = document.createElement("a");
		        var id = DirInfo.ID;
			    a.href = "javascript:LeftMenu.OnItemTextClick(" + DirInfo.ID + ",'" + DirInfo.Name+"'," + DiryList.ParentID + ");";
		        a.innerHTML = DirInfo.Name;
	        }
	        else    //如果还有下级节点
	        {
		        var li = document.createElement("li");
		        li.className = "Closed";
		        li.id = "li_" + DirInfo.ID;
    			
    			li.innerHTML = '<img src="../../css/s.gif" class="s" id="' + DirInfo.ID + '"  onclick="LeftMenu.OnItemClick('+DirInfo.ID+', \''+DirInfo.Name+'\', '+DiryList.ParentID+')" alt="展开/折叠" />';
//		        var img = document.createElement("img");
//		        img.id = DirInfo.ID;
//		        img.className = "s";
//		        img.src = "../../css/s.gif";
//		        img.onclick = function () {
//			        LeftMenu.OnItemClick(DirInfo.ID, DirInfo.Name, DiryList.ParentID);
//		        };
//		        img.alt = "展开/折叠";
    			
		        var a = document.createElement("a");
			    a.href = "javascript:LeftMenu.OnItemTextClick(" + DirInfo.ID + ",'" + DirInfo.Name+"'," + DiryList.ParentID + ");";
		        a.innerHTML = DirInfo.Name;
	        }
	        //li.appendChild(img);
	        li.appendChild(a);
	        ul.appendChild(li);	
	        objParent.appendChild(ul);
	    }
    }
}

//展开文件夹
LeftMenu.OnItemClick = function(intDirID, strDirName, intParentID)
{
    var obj = document.getElementById("li_" + intDirID);
    if (obj.className == "Closed")
    {
	    obj.className = "Opened";
    }
    else
    {
	    obj.className = "Closed";
    }
    
    CViewMgr.sm_viewMgr.m_viewLeftMenu.m_object.DirID = intDirID;
    CViewMgr.sm_viewMgr.m_viewLeftMenu.m_object.DirName = strDirName;
    CViewMgr.sm_viewMgr.m_viewLeftMenu.m_object.ParentDirID = intParentID;
    
    //{DirID:0, DirName:"",ParentDirID:0, tol:0 ,nCurPage:1,nPageSize:8};
    
    CControl.sm_instance.OnMessage("LeftMenuOnClick", CControl.sm_ActionList.clickMenuItem, CViewMgr.sm_viewMgr.m_viewLeftMenu.m_object);
}

//点击对应的文件夹
LeftMenu.OnItemTextClick = function(intDirID, strDirName, intParentID)
{
    CViewMgr.sm_viewMgr.m_viewLeftMenu.m_object.DirID = intDirID;
    CViewMgr.sm_viewMgr.m_viewLeftMenu.m_object.DirName = strDirName;
    CViewMgr.sm_viewMgr.m_viewLeftMenu.m_object.ParentDirID = intParentID;
    
    //{DirID:0, DirName:"",ParentDirID:0, tol:0 ,nCurPage:1,nPageSize:8};
    
    CControl.sm_instance.OnMessage("LeftMenuOnClick", CControl.sm_ActionList.clickMenuItemText, CViewMgr.sm_viewMgr.m_viewLeftMenu.m_object);
}